package com.cai.primeton.router;

import com.cai.primeton.entity.PBook;
import com.cai.primeton.entity.PType;
import com.cai.primeton.repository.BookRepo;
import com.cai.primeton.repository.CategoryRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @version 1.0
 * @author：蔡松坡
 * @date：2021/7/5 11 : 32
 * @package：com.cai.primeton.router
 */
@Controller
public class Public {

    @Autowired
    private BookRepo bookRepo;

    @Autowired
    private CategoryRepo categoryRepo;

    @RequestMapping("/router/login")
    public String login(){

        return "login";
    }

    @RequestMapping("/router/main")
    public String main(){

        return "main";
    }
    @RequestMapping("/book/list")
    public String list(Model model){
        List<PBook> all = bookRepo.findAll();
        model.addAttribute("books",all);
        return "booklist";
    }

    @RequestMapping("/book/add")
    public String add(Model model){
        List<PType> all = categoryRepo.findAll();
        model.addAttribute("pTypes",all);
        return "addbook";
    }
}
